package org.homly.admin.tag.product;

import java.util.HashMap;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.homly.sql.SQLTool;

public class ProductDetailTag extends TagSupport {

	private String name = "rows";
	private String productId = null;

	@Override
	public int doStartTag() throws JspException {

		if(productId != null && !productId.equals("")) {
			String sql = " select * from product where product_id=" + Integer.parseInt(productId);
			try {
				List<HashMap<String, String>> list = SQLTool.query(sql);
				if(list != null && list.size() > 0) {
					pageContext.setAttribute(name, (HashMap<String, String>)list.get(0));
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return super.doStartTag();
	}
	
	

	public void setProductId(String productId) {
		this.productId = productId;
	}

	public void setName(String name) {
		this.name = name;
	}

}
